<template>
  <el-row>
    <el-form label-position="left" label-width="120px">
      <el-col :span="24">
        <Portlet title="费用信息">
          <el-table
            v-if="filterData.length > 0"
            border
            max-height="500"
            :data="filterData"
            class="text-center"
            :header-cell-style="{'text-align': 'center'}"
            :cell-style="{'text-align': 'center'}"
            :summary-method="getSummariesCostList"
            show-summary
          >
            <el-table-column
              align="center"
              prop="clearingObjectName"
              label="结算主体"
            >
            </el-table-column>
            <el-table-column
              prop="serviceNo"
              label="费用名称">
              <template slot-scope="scope">
                {{ filterData[scope.$index]['serviceNo'] | filterDataBaseDictionary}}
              </template>
            </el-table-column>
            <el-table-column
              prop="money"
              align="center"
              label="应收金额">
            </el-table-column>
          </el-table>
          <div v-if="!filterData.length"> 无</div>
        </Portlet>
      </el-col>
    </el-form>
  </el-row>
</template>
<script>
import {decimalNumFilter} from '@/filters'
export default {
  props: {
    detail: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
    }
  },
  computed: {
    filterData() {
      return this.detail.filter(v => v.money) || []
    }
  },
  methods: {
    // 合计
    getSummariesCostList(param) {
      const {columns, data} = param
      const sums = []
      columns.forEach((column, index) => {
        const values = data.map(item => Number(item[column.property]))
        if (index === 0) {
          sums[index] = '合计'
        } else {
          if (column.property === 'money') {
            let temp = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = decimalNumFilter(temp, column.property === 'money' ? 0 : 2)
          } else {
            sums[index] = ''
          }
        }
      })
      return sums
    }
  }
}
</script>
